<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>左图</title>
    <link rel="stylesheet" type="text/css" href="__CSS__api.css" />
    <link rel="stylesheet" type="text/css" href="__CSS__aui.css" />
    <style>
        body{
            background-color: #FFFFFF;
        }
        .warrp{
            width: 100%;
            height: 100%;
            padding: 1.4rem 1.5rem 0 1.5rem;
        }
        .title{
            width: 100%;
            height: 3.5rem;
            font-size:1.15rem;
            color: #333333;
            line-height:1.15rem;
            padding-bottom:2.4rem;
            font-weight: bold;
        }
        .phone{
            margin-top: 0.8rem;
            font-size:0.7rem;
            color:#333333;
            line-height:0.6rem;
            font-weight: bold;
        }
        .shuru{
            width: 100%;
            height: 2.35rem;
            line-height: 2.35rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .code1{
            width: auto;
            height: 2.25rem;
            font-size:0.65rem;
            color:#B3B3B3;
            line-height:2.35rem;
            text-align: center;
        }
        .code{
            width: auto;
            height: 2.35rem;
            font-size:0.65rem;
            color:#E73C5C;
            line-height:2.35rem;
            text-align: center;
        }
        input[type="text"], input[type="password"], input[type="tel"] {
            width: 9rem;
            height: 2.25rem;
            line-height:auto;
            color: #010101;
            background: none;
            outline: none;
            font-size: 0.8rem;
            font-weight: 600;
            padding: 0 0 0 0;
            margin: 0 0 0 0;
        }

        input::-webkit-input-placeholder {
            color: #B3B3B3;
            font-size: 0.75rem;
            font-weight: normal;
        }
        .login-btn{
            margin-top: 2.25rem;
            width:100%;
            height:2.5rem;
            background:#E73C5C;
            border-radius:5px;
            font-size:0.8rem;
            color:#FFFFFF;
            line-height:2.5rem;
            text-align: center;
            font-weight: bold;
        }
        .zhuce{
            height: 0.65rem;
            font-size:0.7rem;
            color: #E73C5C;
            line-height:0.65rem;
            margin-top: 0.9rem;
            float: right;
        }
        .sanfang{
            width: 100%;
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-top: 3.55rem;
        }
        .tu img{
            width: 2.25rem;
            height: 2.25rem;
        }
        .xieyi{
            width: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            margin-top: 9.3rem;
        }
        .xiaobiao{
            width: 0.75rem;
            height: 0.75rem;
        }
        .tongyi{
            font-size: 0.65rem;
            color: #999999;
            font-size: 0.6rem;
        }
        .tongyi span{
            color: #E73C5C;
        }
        input[type="checkbox"] {
            -webkit-appearance: none;
            width: 15px;
            height: 15px;
            vertical-align: middle;
            background: #fff;
            background:url('__IMG__uncheck.png') no-repeat center center;
            background-size: 15px 15px;
            background-size: 15px 15px;
            border-radius: 50%;
            margin-right:6.5px;
            margin-top:-1.5px;
        }
        input[type="checkbox"]:checked {
            -webkit-appearance: none;
            width: 15px;
            height: 15px;
            vertical-align: middle;
            background:url('__IMG__xuanzhong.png') no-repeat center center;
            background-size: 15px 15px;
            border-radius: 50%;
        }
    </style>
</head>

<body>
<div class="warrp">
    <div class="title">
        绑定手机号
    </div>
    <div class="phone">
        手机号
    </div>
    <div class="shuru underLine">
        <input type="tel" name="phone" placeholder="请输入手机号" id="phone"  maxlength="11" onkeyup="value=value.replace(/[^0-9]/g,'')" onpaste="value=value.replace(/[^0-9]/g,'')" oncontextmenu="value=value.replace(/[^0-9]/g,'')">
       <a href="javascript:void(0)" onclick="need_ma()">
        <div class="code"  id='code'  tapmode="active">
            发送验证码
        </div>
       </a>
    </div>
    <div class="phone">
        验证码
    </div>
    <div class="shuru underLine">
        <input type="tel" name="code" placeholder="请输入验证码" id='codeValue' maxlength="6" >
    </div>
    <div class="login-btn" onclick="login()" tapmode>
        绑定
    </div>
    <div class="xieyi">
        <input type="checkbox" name="read" checked  id="checkType" class="checkbox">
        <div class="tongyi">
            我已阅读并同意<span>“用户协议”</span>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="__JS__jquery.min.js"></script>
<script type="text/javascript" src="__JS__api.js"></script>
<script type="text/javascript" src="__JS__api.js"></script>
<script type="text/javascript" src="__JS__tt.js"></script>
<script type="text/javascript" src="__JS__layer_mobile/layer.js"></script>
<script type="text/javascript">
    var onClickTime;//点击时间
    var onClickTime1;//当前时间

    // 发送验证码
    var isOnclick = true;
    function need_ma () {
        var phone = $api.byId('phone').value;
        var regBox = {
            regMobile: /^\d{11}$/ //手机
        };
        var rPhone = regBox.regMobile.test(phone);
        if (!(rPhone && phone)) {
            layer.open({
                content:'请输入正确手机号',
                skin: 'msg'
                ,time: 3 //2秒后自动关闭
            });
            return;

        }
        if (isOnclick) {
            //调用接口判断
            sendSMS(phone);
        }
    }

    //获取验证码
    function sendSMS (phone) {
        $.ajax({
            url:'{:url("My/getPhoneCode")}',
            data:{'phone':phone},
            type:'POST',
            dataType:'JSON',
            success:function (data) {
            if (data.status == 200) {
                layer.open({
                    content:'发送成功',
                    skin: 'msg'
                    ,time: 3 //2秒后自动关闭
                });
                if (isOnclick) {
                    onClickTime=Math.floor((new Date().getTime())/1000);
                    isinerval = setInterval('CountDown()', 1000);
                    isOnclick = false;
                }
            }else{
                layer.open({
                    content: data.msg
                    ,skin: 'msg'
                    ,time: 3 //2秒后自动关闭
                });
            }
        }
    })
//        doAjax(GETPHONECODE, 'POST', parame, function (successData) {
//            LoadingClose();
//            if (successData.status == '200') {
//                layer.open({
//                    content:'发送成功',
//                    skin: 'msg'
//                    ,time: 3 //2秒后自动关闭
//                });
//                if (isOnclick) {
//                    onClickTime=Math.floor((new Date().getTime())/1000);
//                    isinerval = setInterval('CountDown()', 1000);
//                    isOnclick = false;
//                }
//
//            } else {
//
//                layer.open({
//                    content:'发送成功',
//                    skin: 'msg'
//                    ,time: 3 //2秒后自动关闭
//                });
//
//            }
//
//        }

    }

    //验证码60秒倒数
    function CountDown () {
        onClickTime1=60-(Math.floor((new Date().getTime())/1000)-onClickTime);
        var code = $api.byId('code');
        $api.removeCls(code, 'code');
        $api.addCls(code, 'code1');
        if (onClickTime1 < 1) {
            $api.html(code, '重新获取');
            clearInterval(isinerval);
            isOnclick = true;
            return;
        }
        $api.html(code, '倒计时' + onClickTime1 + 's');

    }
    function login() {
      var code = $('input[name="code"]').val();
      var phone = $('input[name="phone"]').val();
        $.ajax({
            url:'{:url("My/ajaxBandPhone")}',
            data:{'phone':phone,'code':code},
            type:'POST',
            dataType:'JSON',
            success:function (data) {
                if(data.status == 200){
                    location.href = '{:url("First/index")}';
                }else{
                    layer.open({
                        content: data.msg
                        ,skin: 'msg'
                        ,time: 3 //2秒后自动关闭
                    });
                }
            }
        })
    }
</script>
</html>
